// pages/user/loveShop/loveShop.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shopArr: [0, 1, 2, 3, 4, 5],
    imgURL: app.globalData.imgURL,//图片总路径

  },

  //删除店铺
  deleteShopClick:function(e){
    var that = this;

    wx.showModal({
      title: '温馨提示',
      content: '是否要删除此收藏店铺？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          that.deleteRequest(e.currentTarget.id);
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  //删除店铺请求
  deleteRequest: function (shopID){
    var that = this;
    app.post('collect/del', { openId: wx.getStorageSync('userInfo').userId, shopId: shopID }).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        that.requestData();
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },

  shopClick:function(e){
    wx.navigateTo({
      url: '../../home/shopMessage/shopMessage?id=' + e.currentTarget.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.requestData();
  },

  //请求数据
  requestData:function(){
    var that = this;
    app.post('collect/list', { openId: wx.getStorageSync('userInfo').userId }).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        that.setData({
          shopArr: res.resultData,
        })
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})